package com.example.smartcity_poverty.ui.AllService.SmartBus.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.util.Util
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.android.synthetic.main.activity_smart_city_two.*

class SmartCityTwoActivity : AppCompatActivity() {

    private val id by lazy { intent.getStringExtra("id")?.toInt() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_smart_city_two)
        title = "选择出行日期"
        Util.addActivity(this)

        var strTime: String? = null

        // 选择日期
        var ff = false
        busTwoTime.setOnDateChangeListener { _, i, i2, i3 ->
            runOnUiThread {
                busTwoTvTime.text = "出行日期: ${i}年 ${i2}月 ${i3}日"
                strTime = "${i}年 ${i2}月 ${i3}日"
                ff = true
            }
        }

        // 选择好日期进入下一页
        busTwoOk.setOnClickListener {
            if (ff){
                startActivity(Intent(this, SmartBusThreeActivity::class.java).apply {
                    putExtra("id", id.toString())
                    putExtra("time", strTime.toString())
                })
            }else "你还没选择日期！".show()

        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}